﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CasterDPSMeter
{
    public partial class MainForm : Form
    {
        internal Player _player;

        public MainForm()
        {
            InitializeComponent();
            _player = new Player();
        }

        private void bonusDamage_Leave(object sender, EventArgs e)
        {
            int value;
            if (string.IsNullOrEmpty(bonusDamage.Text)) value = 0;
            else value = Int32.Parse(bonusDamage.Text);
            _player.BonusDamage.SetAll(value);
            bonusDamage.Text = _player.BonusDamage.GetBonusDamage().ToString();
        }

        private void browseBonusDamage_Click(object sender, EventArgs e)
        {
            using (BonusDamageDialog form = new BonusDamageDialog())
            {
                form.Player = _player;
                if (form.ShowDialog(this) == DialogResult.OK)
                {
                    bonusDamage.Text = _player.BonusDamage.GetBonusDamage().ToString();
                }
            }
        }

        private void critChance_Leave(object sender, EventArgs e)
        {
            double value;
            if (string.IsNullOrEmpty(critChance.Text)) value = 0.0;
            else value = Double.Parse(critChance.Text.TrimEnd('%'));
            _player.CritChance.SetAll(value);
            critChance.Text = _player.CritChance.GetCritChance().ToString();
        }

        private void browseCritChance_Click(object sender, EventArgs e)
        {
            using (CritChanceDialog form = new CritChanceDialog())
            {
                form.Player = _player;
                if (form.ShowDialog(this) == DialogResult.OK)
                {
                    critChance.Text = _player.CritChance.GetCritChance().ToString();
                }
            }
        }

        private void updateStats_Click(object sender, EventArgs e)
        {
            _player.BonusHealing = Int32.Parse(bonusHealing.Text);
            _player.HitRating = Int32.Parse(hitRating.Text);
            _player.SpellHasteRating = Int32.Parse(spellHasteRating.Text);
            // TODO: update already casted spells...
        }

        private void armorySync_Click(object sender, EventArgs e)
        {
            using (CharacterSelector form = new CharacterSelector())
            {
                if (form.ShowDialog(this) == DialogResult.OK)
                {
                    _player = form.GetPlayerFromArmory();
                }
            }
        }
    }
}
